package com.weipai.springboot.module.service.impl;

import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.Customer;
import com.weipai.springboot.model.ReputationHistory;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.dao.ReputationHistoryDao;
import com.weipai.springboot.module.service.ReputationHistoryService;
import com.weipai.springboot.module.util.SessionUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author songmengqiang
 * @create 2018-09-26 18:24
 **/
@Service
public class ReputationHistoryServiceImpl implements ReputationHistoryService {

    @Autowired
    private ReputationHistoryDao reputationHistoryDao;
    @Autowired
    private SessionUserUtil sessionUserUtil;

    @Override
    public Response save(ReputationHistory reputationHistory) {
        Response response = new Response();
        if (1 == reputationHistoryDao.save(reputationHistory)) {
            response.setCode(RetCode.SUCCESS);
        } else {
            response.setCode(RetCode.SAVE_ERROR);
        }
        return response;
    }

    @Override
    public Response queryByCustomerId() {
        Response response = new Response();
        Customer customer = sessionUserUtil.getUserAttr();
        List<ReputationHistory> list = reputationHistoryDao.queryByCustomerId(customer.getCustomerId());
        response.put("list", list);
        response.setCode(RetCode.SUCCESS);
        return response;
    }
}
